package com.xjtu.chapter09;

import java.util.ArrayList;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/9/2 21:02
 */
class Chicken {
    int chickenNum;

    public Chicken(int i) {
        chickenNum = i;
    }

    public void show() {
        System.out.println("Chicken id: " + chickenNum);
    }
}

public class GenericTest2 {
    public static void main(String[] args) {
//        ArrayList animals = new ArrayList();//定义一个ArrayList animals
//        for (int i = 0; i < 5; i++) {
//            animals.add(new Chicken(i));
//        }
//        for (int j = 0; j < 5; j++) {
//            ((Chicken) animals.get(j)).show();
//        }
        //泛型
        ArrayList<Chicken>animals = new ArrayList<Chicken>();
        for (int i = 0; i < 5; i++) {
            animals.add(new Chicken(i));
        }
        for (int j = 0; j < 5; j++) {
           animals.get(j).show();
        }
    }
}
